<template>
  <div class="content">
    <div class="cloud-header">
      <h2>卡券核销记录</h2>
    </div>
    <div class="cloud-body">
      <div class="cloud-subset-title">
        <div class="cloud-subset-action">
        </div>
        <!-- <p class="cloud-subset-tips">在开发的场景同，通常一个项目管理多个应用，如微信公众号，微信小程序，数据后台等等公用的一个数据库，此处用于区分不同应用场景<br></p> -->
      </div>
      <Table :datas="datas" :stripe="true" :loading="loading">
        <TableItem title="卡券号" :width="260" prop="cardId"> </TableItem>
        <TableItem title="卡券类型">
          <template slot-scope="{data}">
            {{ available_type(data.type)}}
          </template>
        </TableItem>
        <TableItem title="领券人">
          <template slot-scope="{data}">
            {{ data.users[0].nickname}}
          </template>
        </TableItem>
        <TableItem title="状态">
          <template slot-scope="{data}">
            {{available_state(data.status)}}
          </template>
        </TableItem>
        <TableItem title="领取时间">
          <template slot-scope="{data}">
            {{data.creation_time}}
          </template>
        </TableItem>
        <TableItem title="核销时间">
          <template slot-scope="{data}">
            {{ data.use_time}}
          </template>
        </TableItem>
        <!-- <TableItem title="操作">
          <template slot-scope="{data}">
            -
          </template>
        </TableItem> -->
        <div slot="empty">自定义提醒：暂时无数据</div>
      </Table>
      <Pagination style="margin-top: 20px;" v-model="pagination" align="center" @change="currentChange" small></Pagination>
    </div>
  </div>
</template>
<script type="text/javascript">
// import empty from './empty.vue'
export default {
  components: {
    // empty
  },
  data() {
    return {
      loading: false,
      datas: [],
      //分页数据
      pagination: {
        page: 1,
        size: 10,
        total: 10
      }
    };
  },
  /**
   * 计算属性
   * @type {Object}
   */
  computed: {

  },
  /**
   * 页面渲染前
   * @return {[type]} [description]
   */
  created() {

  },
  /**
   * 数据监听
   * @type {Object}
   */
  watch: {

  },
  /**
   * 页面加载执行
   * @return {[type]} [description]
   */
  mounted() {
    this.dataCount();
    this.dataList();
  },
  methods: {
    dataList() {
      let userInfo = this.$cloud.userInfo();
      this.$cloud.view('card_log', 'users', '_userid = _id').where({ '_uniqueid': userInfo._uniqueid, 'status': '2' }).order('use_time DESC').page(this.pagination.page, this.pagination.size).select().then(data => {
        console.log('查看', data);
        this.datas = data;
      }).catch(error => {

      });
    },
    dataCount() {
      let userInfo = this.$cloud.userInfo();
      this.$cloud.view('card_log', 'users', '_userid = _id').where({ '_uniqueid': userInfo._uniqueid, 'status': '2' }).count().then(res => {
        this.pagination.total = res
      }).catch(error => {

      });
    },
    //分页
    currentChange(value) {
      this.pagination = value
      this.dataList()
    },
    available_type(value) {
      switch (value) {
        case 'DISCOUNT':
          return '折扣券';
        case 'GIFT':
          return '兑换券';
        case 'CASH':
          return '代金券';
      }
    },
    available_state(value) {
      switch (value) {
        case '1':
          return '待使用';
        case '2':
          return '已使用';
        case '3':
          return '已失效';
      }
    },
    onDelete() {

    },
    formatDate(date) {
      var date = new Date(date);
      var YY = date.getFullYear() + '-';
      var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
      var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
      var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
      var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
      var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
      return YY + MM + DD + " " + hh + mm + ss;
    }
  }
};

</script>
<style lang="less" scoped="true">
</style>
